package com.alex.springbootdemo.utils;

import cn.hutool.core.util.ObjectUtil;
import com.alex.springbootdemo.common.ResultCode;
import com.alex.springbootdemo.exception.AssertException;
import org.apache.commons.lang.StringUtils;

public class AssertUtil {

    public static void isTrue(boolean expression, String msg) {
        if (!expression) {
            throw new AssertException(msg);
        }
    }

    public static void isTrue(boolean expression, ResultCode resultCode) {
        if (!expression) {
            throw new AssertException(resultCode);
        }
    }

    public static void isTrue(boolean expression, ResultCode resultCode, String errMsg) {
        if (!expression) {
            if (StringUtils.isNotEmpty(errMsg)) {
                throw new AssertException(errMsg);
            }
            throw new AssertException(resultCode);
        }
    }

    public static void isFalse(boolean expression, String msg) {
        if (expression) {
            throw new AssertException(msg);
        }
    }

    public static void isFalse(boolean expression, ResultCode resultCode) {
        if (expression) {
            throw new AssertException(resultCode);
        }
    }

    public static void isFalse(boolean expression, ResultCode resultCode, String errMsg) {
        if (expression) {
            if (StringUtils.isNotEmpty(errMsg)) {
                throw new AssertException(errMsg);
            }
            throw new AssertException(resultCode);
        }
    }

    public static void isNull(Object obj, String msg) {
        if (ObjectUtil.isNotNull(obj)) {
            throw new AssertException(msg);
        }
    }

    public static void isNull(Object obj, ResultCode resultCode) {
        if (ObjectUtil.isNotNull(obj)) {
            throw new AssertException(resultCode);
        }
    }

    public static void isNull(Object obj, ResultCode resultCode, String errMsg) {
        if (ObjectUtil.isNotNull(obj)) {
            if (StringUtils.isNotEmpty(errMsg)) {
                throw new AssertException(errMsg);
            }
            throw new AssertException(resultCode);
        }
    }

    public static void isNotNull(Object obj, String msg) {
        if (ObjectUtil.isNull(obj)) {
            throw new AssertException(msg);
        }
    }

    public static void isNotNull(Object obj, ResultCode resultCode) {
        if (ObjectUtil.isNull(obj)) {
            throw new AssertException(resultCode);
        }
    }

    public static void isNotNull(Object obj, ResultCode resultCode, String errMsg) {
        if (ObjectUtil.isNull(obj)) {
            if (StringUtils.isNotEmpty(errMsg)) {
                throw new AssertException(errMsg);
            }
            throw new AssertException(resultCode);
        }
    }


    public static void isEmpty(Object obj, String msg) {
        if (ObjectUtil.isNotEmpty(obj)) {
            throw new AssertException(msg);
        }
    }

    public static void isEmpty(Object obj, ResultCode resultCode) {
        if (ObjectUtil.isNotEmpty(obj)) {
            throw new AssertException(resultCode);
        }
    }

    public static void isEmpty(Object obj, ResultCode resultCode, String errMsg) {
        if (ObjectUtil.isNotEmpty(obj)) {
            if (StringUtils.isNotEmpty(errMsg)) {
                throw new AssertException(errMsg);
            }
            throw new AssertException(resultCode);
        }
    }

    public static void isNotEmpty(Object obj, String msg) {
        if (ObjectUtil.isEmpty(obj)) {
            throw new AssertException(msg);
        }
    }

    public static void isNotEmpty(Object obj, ResultCode resultCode) {
        if (ObjectUtil.isEmpty(obj)) {
            throw new AssertException(resultCode);
        }
    }

    public static void isNotEmpty(Object obj, ResultCode resultCode, String errMsg) {
        if (ObjectUtil.isEmpty(obj)) {
            if (StringUtils.isNotEmpty(errMsg)) {
                throw new AssertException(errMsg);
            }
            throw new AssertException(resultCode);
        }
    }
}
